package jjn.daily;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023-09-26 21:54
 */
public class LeetCode2582 {
    public int passThePillow(int n, int time) {
        // 1 - n -> n
        // n - 1 -> n
        if (n == 1) {
            return 1;
        }
        int rest = time % (2* n - 2);
        if (rest < n) {
            return rest + 1;
        }
        rest = rest % n;
        return n - rest - 1;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int time = scanner.nextInt();
        int passed = new LeetCode2582().passThePillow(n, time);
        System.out.println(passed);
    }
}
